import 'package:dio/dio.dart';
import 'package:handwrite/bean/CharacterBean.dart';
import 'package:handwrite/request/NetworkService.dart';

class CommonApi {
  static Future submit(String filePath, String character) async {
    var res = await NetworkService.post(
        url: "upload",
        map: {
          "file": MultipartFile.fromFileSync(filePath),
          "character": character
        },
        useFormData: true);
  }

  static Future<String> check(String text) async {
    var res = await NetworkService.post(
        url: "check",
        map: {"text": text.split('').toSet().join("")},
        useFormData: true);
    return "${res.data}";
  }

  static Future<List<CharacterBean>> getFiles(String text) async {
    var res = await NetworkService.post(
        url: "getFiles", map: {"text": text}, useFormData: true);
    return res.getTypedList((map) => CharacterBean.fromJson(map)) ?? [];
  }
}
